home *** CD-ROM | disk | FTP | other *** search
/ Gekkan Dennou Club 140 / Gekkan Dennou Club - 2000.1 Vol. 140 (Japan).7z / Gekkan Dennou Club - 2000.1 Vol. 140 (Japan) (Track 1).bin / tools / dshell / dsh333bs.lzh / rgb.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-07-11  |  6.0 KB  |  336 lines

  1. /*
  2.     dshell    v3
  3.  
  4.     画面色調整
  5. */
  6.  
  7. #include    "dsh.h"
  8.  
  9. static void rgb_select(int );
  10. static void disp_rgbbar(int , int , int );
  11. static void disp_rgb(int, int, ushort [3]);
  12.  
  13.  
  14. void 
  15. Menu_rgb()
  16. {
  17. #define        ITEMS        9    /* アイテムの数 */
  18. #define        MAX_MESLEN    6    /* 一番長いメッセージのバイト数 */
  19.  
  20. #define        WIN_SX        29    /* ウィンドウ開位置X */
  21. #define        WIN_SY        (31 - ITEMS - 1)    /* 同Y */
  22.  
  23.     static const uchar *mes[ITEMS] =
  24.     {
  25.         " テキスト3",
  26.         " テキスト2",
  27.         " テキスト1",
  28.         "主背景",
  29.         "上下帯",
  30.         "メニュー地",
  31.         "スケール地",
  32.         " スケール ",
  33.         " 終了 "
  34.     };
  35.  
  36.     /*
  37.     !    枠の表示
  38.     !    マウスエリアの設定
  39.     */
  40.     tbox_w2(WIN_SX, WIN_SY, WIN_SX + MAX_MESLEN, WIN_SY + ITEMS);
  41.  
  42.  
  43.     /*
  44.     !    アイテムの表示
  45.     */
  46.     B_COLOR(3);
  47.     {
  48.         int i;
  49.  
  50.         for (i = 0; i < ITEMS; i++) {
  51.             B_LOCATE(WIN_SX, WIN_SY + i);
  52.             B_PRINT(mes[i]);
  53.         }
  54.     }
  55.  
  56.     /*
  57.     !    マウス離されるの待ち
  58.     */
  59.     wait_mb_off();
  60.     /*
  61.     !    アイテムセレクト
  62.     */
  63.     while (1) {
  64.         int dmx, dmy, mx, my, omy = -1, mbl, mbr;
  65.         int selected = -1;
  66.  
  67.         msarea(WIN_SX * 8, WIN_SY * 16, (WIN_SX + MAX_MESLEN) * 8, (WIN_SY + ITEMS) * 16);
  68.         do {
  69.             p_time(0);
  70.             dmsstat(&dmx, &dmy, &mbl, &mbr);
  71.             dmspos(&mx, &my);
  72.             {
  73.                 int i;
  74.  
  75.                 for (i = 0; i < ITEMS; i++) {
  76.                     if (my > (WIN_SY + i) * 16 && my < (WIN_SY + i + 1) * 16 && omy != i) {
  77.                         int j;
  78.  
  79.                         for (j = 0; j < ITEMS; j++) {
  80.                             B_LOCATE(WIN_SX, WIN_SY + j);
  81.                             B_PRINT(mes[j]);
  82.                         }
  83.                         B_COLOR(13);    /* 水色反転 */
  84.                         B_LOCATE(WIN_SX, WIN_SY + i);
  85.                         B_PRINT(mes[i]);
  86.                         B_COLOR(3);
  87.                         omy = i;
  88.                         selected = i;
  89.                         break;
  90.                     }
  91.                 }
  92.             }
  93.         } while (!(mbl || mbr));
  94.  
  95.         /*
  96.         !    キャンセルか?
  97.         */
  98.         if (mbr == -1) {
  99.             selected = -1;
  100.         }
  101.         /*
  102.         !    選択されていたら色設定へ
  103.         */
  104.         if (selected != -1 && selected != ITEMS - 1) {
  105.             rgb_select(selected - 3);
  106.         } else {
  107.             /*
  108.             !    色設定を終了
  109.             */
  110.             break;
  111.         }
  112.     }
  113.  
  114.  
  115.     /*
  116.     !    ウィンドウを元に戻す
  117.     */
  118.     msarea(0, 0, GWIDTH - 1, 511);
  119.     {
  120.         int i;
  121.  
  122.         for (i = WIN_SY - 2; i <= 29; i++) {
  123.             p_lin(lp + i, i);
  124.         }
  125.     }
  126.  
  127.     /*
  128.     !    マウス離されるの待ち
  129.     */
  130.     wait_mb_off();
  131.  
  132.  
  133. #undef        ITEMS
  134. #undef        MAX_MESLEN
  135. #undef        WIN_SX
  136. #undef        WIN_SY
  137.  
  138. }
  139.  
  140.  
  141. /*
  142.     指定されたパレットを変更する
  143. */
  144. static void 
  145. rgb_select(int pal_no)
  146. {
  147. #define        ITEMS        5
  148.  
  149.     static const uchar *scr[ITEMS] =
  150.     {
  151.         "R------------------------------- [00]",
  152.         "G------------------------------- [00]",
  153.         "B------------------------------- [00]",
  154.         "",
  155.         "  初期値       Code ?:XXXX  設定  中止"
  156.     };
  157.     int dmx, dmy, mx, my, mbl, mbr;
  158.     ushort ocolor_code, color_code;
  159.     ushort c[3];
  160. #define    r    (c[0])
  161. #define    g    (c[1])
  162. #define    b    (c[2])
  163.  
  164. #define        WIN_SX        36
  165. #define        WIN_SY        24
  166.  
  167.  
  168. #define        MAX_MESLEN    39
  169.     tbox_w2(WIN_SX, WIN_SY, WIN_SX + MAX_MESLEN, WIN_SY + ITEMS);
  170.     msarea(WIN_SX * 8, WIN_SY * 16, (WIN_SX + MAX_MESLEN) * 8, (WIN_SY + ITEMS) * 16);
  171.  
  172.  
  173.     /*
  174.     !    初期画面設定
  175.     */
  176.     {
  177.         int i;
  178.  
  179.         for (i = 0; i < ITEMS; i++) {
  180.             B_LOCATE(WIN_SX, WIN_SY + i);
  181.             B_PRINT(scr[i]);
  182.         }
  183.         B_LOCATE(WIN_SX + 2, WIN_SY + ITEMS - 1);
  184.         B_COLOR(6);
  185.         B_PRINT((uchar *) "初期化");
  186.         B_COLOR(3);
  187.     }
  188.  
  189.     /*
  190.     !    現在値の表示
  191.     */
  192.     color_code = ocolor_code = dpalet(pal_no, -1);
  193.     disp_rgb(pal_no, color_code, c);
  194.  
  195.     wait_mb_off();
  196.  
  197.     /*
  198.     !    設定開始
  199.     */
  200.     {
  201.  
  202.         while (1) {
  203.             p_time(0);
  204.             dmsstat(&dmx, &dmy, &mbl, &mbr);
  205.             dmspos(&mx, &my);
  206.  
  207.             if (mbr == -1) {    /* 右ボタンでキャンセルしたか? */
  208.                 dpalet(pal_no, ocolor_code);
  209.                 break;
  210.             }
  211.             if (mbl == -1) {    /* 左ボタンをクリックしたか? */
  212.                 int i;
  213.  
  214.                 /*
  215.                 !    レベルメータのアクセスチェック
  216.                 */
  217.                 for (i = 0; i < 3; i++) {
  218.                     if (my > (WIN_SY + i) * 16 && my < (WIN_SY + i + 1) * 16) {    /* i行目に入っているか? */
  219.                         if (mx > (WIN_SX + 2 - 2) * 8 && mx < (WIN_SX + 2 + 31) * 8) {    /* レベルメータの上か? */
  220.                             int x;
  221.                             char buf[96];
  222.  
  223.                             x = (mx - (WIN_SX + 2) * 8);    /* オフセットピクセルに換算 */
  224.                             x = (x >= 0) ? x / 8 + 1 : 0;    /* メータの0テキスト座標判定 */
  225.                             disp_rgbbar(WIN_SX + 2, WIN_SY + i, x);    /* レベルの表示 */
  226.                             c[i] = x;
  227.                             color_code = (r << 6 | g << 11 | b << 1);
  228.                             dpalet(pal_no, color_code);
  229.                             B_LOCATE(WIN_SX + 20, WIN_SY + ITEMS - 1);
  230.                             sprintf(buf, "%1d:%04X", pal_no, color_code);
  231.                             B_PRINT(buf);
  232.                         }
  233.                     }
  234.                 }
  235.  
  236.                 /*
  237.                 !    決定又は中止
  238.                 */
  239.                 if (my > (WIN_SY + ITEMS - 1) * 16 && my < (WIN_SY + ITEMS) * 16) {    /* 項目行に入っているか? */
  240.                     if (mx > (WIN_SX + 28) * 8 && mx < (WIN_SX + 28 + 4) * 8) {    /* 設定 */
  241.                         if (pal_no < 0)
  242.                             tx_col[-pal_no] = color_code;
  243.                         else
  244.                             gr_col[pal_no] = color_code;
  245.                         break;
  246.                     }
  247.                     if (mx > (WIN_SX + 34) * 8 && mx < (WIN_SX + 34 + 4) * 8) {    /* 中止 */
  248.                         dpalet(pal_no, ocolor_code);
  249.                         break;
  250.                     }
  251.                     if (mx > (WIN_SX + 2) * 8 && mx < (WIN_SX + 2 + 6) * 8) {    /* 初期値 */
  252.                         if (pal_no < 0)
  253.                             color_code = otx_col[-pal_no];
  254.                         else
  255.                             color_code = ogr_col[pal_no];
  256.                         dpalet(pal_no, color_code);
  257.                         disp_rgb(pal_no, color_code, c);
  258.                         /*    break;    しない */
  259.                     }
  260.                 }
  261.             }
  262.         }
  263.     }
  264.  
  265.  
  266.     /*    getch();    */
  267.  
  268.     /*
  269.     !    画面初期化
  270.     */
  271.     {
  272.         int i;
  273.  
  274.         for (i = 0; i < ITEMS; i++) {
  275.             B_LOCATE(WIN_SX, WIN_SY + i);
  276.             B_PRINT(scr[i]);
  277.         }
  278.     }
  279.     wait_mb_off();
  280.  
  281. }
  282.  
  283. /*
  284.     RGBの成分を棒で表わす
  285.  
  286.     pos=0~2
  287.     len=0~31
  288. */
  289. static void 
  290. disp_rgbbar(int pos_x, int pos_y, int len)
  291. {
  292.     char on = '>',        /* レベルメータの種類 */
  293.       off = '-';
  294.     char buf[96];
  295.  
  296.     B_LOCATE(pos_x, pos_y);
  297.     {
  298.         int i;
  299.  
  300.         for (i = 0; i < len; i++) {
  301.             B_PUTC(on);
  302.         }
  303.         for (i = len; i < 31; i++) {
  304.             B_PUTC(off);
  305.         }
  306.         B_RIGHT(2);
  307.         sprintf(buf, "%02d", len);
  308.         B_PRINT(buf);
  309.     }
  310. }
  311.  
  312.  
  313. static void 
  314. disp_rgb(int pal_no, int color_code, ushort c[3])
  315. {
  316.     char buf[96];
  317.     int i, y;
  318.  
  319.     r = (color_code & 0x07c0) >> 6;
  320.     g = (color_code & 0xf800) >> 11;
  321.     b = (color_code & 0x003e) >> 1;
  322.  
  323.     y = WIN_SY;
  324.     for (i = 0; i < 3; i++)
  325.         disp_rgbbar(WIN_SX + 2, y++, c[i]);
  326.  
  327.     B_LOCATE(WIN_SX + 19, WIN_SY + ITEMS - 1);
  328.     sprintf(buf, "%2d:%04X", pal_no, color_code);
  329.     B_PRINT(buf);
  330. }
  331. #undef    r
  332. #undef    g
  333. #undef    b
  334.  
  335. /* [ EOF ] */
  336.